/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.alarm.overview;

import java.util.Iterator;
import java.util.Map;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class ClientPropertyTable extends JTable {
    private Map values = null;
    private DefaultTableModel model = new DefaultTableModel();

    public ClientPropertyTable() {
        this(null);
    }

    public ClientPropertyTable(Map values) {
        this.values = values;

        this.setModel(model);
        model.addColumn("Key");
        model.addColumn("Value");

        updateData();
    }

    public void setClientProperties(Map values) {
        this.values = values;
        updateData();
    }

    private void updateData() {
        model.setRowCount(0);
        if (values != null) {
            Iterator it = values.keySet().iterator();
            while (it.hasNext()) {
                Object key = it.next();
                Object value = values.get(key);

                model.addRow(new Object[] {key, value});
            }
        }
    }

    public boolean isCellEditable(int row, int col) {
        return false;
    }
}